package cc.rengu.redp.bizimpl.csmc.controller;

import cc.rengu.redp.bizimpl.csmc.domain.OrgCharge;
import cc.rengu.redp.bizimpl.csmc.domain.TCMchntAcctSum;
import cc.rengu.redp.bizimpl.csmc.service.MchntFeeInfoReportService;
import cc.rengu.redp.common.annotation.Log;
import cc.rengu.redp.common.controller.BaseController;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.domain.RedpResponse;
import cc.rengu.redp.common.utils.EasyExcelUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@Api(tags = "业务查询：商户手续费统计报表")
@RestController
@Slf4j
@RequestMapping("/admin/csmc/MchntFeeInfoReport")
public class MchntFeeInfoReportController extends BaseController {


    @Autowired
    private MchntFeeInfoReportService mchntFeeInfoReportService;

    @Log("分页")
    @GetMapping("/list")
    public Map<String, Object> findByPage(QueryRequest request, TCMchntAcctSum tcMchntAcctSum) {
        //使用工具类getDataTable进行设置分页rows和total
        return getDataTable(mchntFeeInfoReportService.findPage(request,tcMchntAcctSum));
    }

    @Log("导出")
    @PostMapping("/gridExport")
    @ResponseBody
    public RedpResponse gridExportAll(QueryRequest request, TCMchntAcctSum tcMchntAcctSum, HttpServletResponse response) {

        try {
            List<TCMchntAcctSum> tcMchntAcctSumList = this.mchntFeeInfoReportService.findTCMchntAcctSumDetail(request, tcMchntAcctSum).getRecords();
            EasyExcelUtil.export(response, tcMchntAcctSumList, "机构分润统计报表");
        } catch (IOException e) {
            String message = "导出Excel失败";
            log.error(message, e);
            return RedpResponse.getInstance().failure().message(message);
        }
        return RedpResponse.getInstance().success().message("导出Excel成功");
    }

}
